package com.sensor.work.config;




import com.sensor.work.entity.Threshold;
import lombok.extern.slf4j.Slf4j;

import java.util.*;
import java.util.stream.Collectors;
@Slf4j
public class DataBoundValueConfig {


    private static    Map<List<String>,Threshold> map = new HashMap<>();

    static {

        List<String> temperature = Arrays.asList("AAA_A","AAAa_A","AAAc_A");
        Threshold temperatureThreshold = new Threshold(80.0F,-80.0F);
        map.put(temperature,temperatureThreshold);



        List<String> airPressure = Arrays.asList("AGA_A","AGAa_A","AGAc_A");
        Threshold airPressureairThreshold = new Threshold(1100F,-400F);
        map.put(airPressure,airPressureairThreshold);


        List<String> relativeHumidity = Arrays.asList("ADA_A","ADAc_A");
        Threshold relativeHumidityThreshold = new Threshold(100F,0F);
        map.put(relativeHumidity,relativeHumidityThreshold);

        List<String> wind = Arrays.asList("AEC_A","AED_A","AEF_A","AEG_A","AEE_A");
        Threshold windThreshold = new Threshold(360F,0F);
        map.put(wind,windThreshold);


        List<String> windSpeed = Arrays.asList("AFC_A","AFD_A","AFAe_A","AFDa_A","AFAa_A");
        Threshold windSpeedThreshold = new Threshold(75.0F,0F);
        map.put(windSpeed,windSpeedThreshold);


        List<String> dewPoint = Arrays.asList("ADB_A");
        Threshold dewPointSpeedThreshold = new Threshold(35.0F,-80F);
        map.put(dewPoint,dewPointSpeedThreshold);


//        List<String> surfaceTemperature = Arrays.asList();
//        Threshold surfaceTemperatureThreshold = new Threshold(80.0F,-80F);
//        map.put(surfaceTemperature,surfaceTemperatureThreshold);
//
//        List<String> grasslandTemperature = Arrays.asList();
//        Threshold grasslandTemperatureThreshold = new Threshold(60.0F,-80F);
//        map.put(grasslandTemperature,grasslandTemperatureThreshold);
//
//
//        List<String> visibility = Arrays.asList();
//        Threshold visibilityThreshold = new Threshold(50000.0F,10F);
//        map.put(visibility,visibilityThreshold);

    }


    /**
     *  是否超过极限值
     * @param value
     * @param arg
     * @return 超过了 false  未超过 true
     */
   public static boolean isExceed(Float value,String arg){
       for (List<String> key : map.keySet()) {
           Threshold threshold = map.get(key);
           for (String string : key) {
               if (arg.equals(string)){

                   return    (Float.compare(value,threshold.getMaxValue())>0 ||  Float.compare(value,threshold.getMinValue())<0)==false;
//                   return  (value >  threshold.getMaxValue() ||value<threshold.getMinValue())==false;
               }
           }
       }
//       log.error("配置中没有的字段---{}---进行了比较",arg);
       return true;
   }





}
